package com.airnews.ticket.util;

import android.app.Activity;
import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.view.Display;
import android.view.Window;


public class PhoneUtils {


	public static String getImsi(Context ctx) {
		TelephonyManager telephonyManager = (TelephonyManager) ctx
				.getSystemService(Context.TELEPHONY_SERVICE);
		return telephonyManager.getSubscriberId();
	}
	


	public static String getMdn(Context ctx) {
		TelephonyManager telephonyManager = (TelephonyManager) ctx
				.getSystemService(Context.TELEPHONY_SERVICE);
		String mdn = telephonyManager.getLine1Number();
		return mdn;
	}
	
	
	public static String getEsn(Context ctx) {
		TelephonyManager tm = (TelephonyManager) ctx
				.getSystemService(Context.TELEPHONY_SERVICE);
		String esn = tm.getDeviceId();//DeviceId(IMEI)
		return esn;
	}
	
	/**
	 * 获取手机MODLE,手机型号
	 */
	public static String getModel() {
		return Build.MODEL;
	}
	
	
	/**
	 * 获取屏幕分辨率
	 * @param mActivity
	 * @return int[]{width,height}
	 */
	public static int[] getResolution(Activity mActivity){
		 Display screen = mActivity.getWindowManager().getDefaultDisplay();
		 return new int[]{screen.getWidth(), screen.getHeight()};
	}
	
	
	/**
	 * 获取状态栏的高度
	 * (需在屏幕显示后台调用)
	 * @param mActivity
	 * @return
	 */
	public static int getStatusBarHeight(Activity mActivity){
		Rect frame = new Rect();  
		mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);  
		return frame.top; 
	}
	
	
	/**
	 * 获取标题栏高度
	 * (需在屏幕显示后台调用)
	 * @param mActivity
	 * @return
	 */
	public static int getTitleBarHeight(Activity mActivity){
		int contentTop = mActivity.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();  
		return contentTop - getStatusBarHeight(mActivity);
	}
	
}
